<template>
  <el-container class="layout-container" style="margin-top: 20px">
    <!-- 左侧菜单 -->
    <el-aside width="200px" style="background-color: #232323;">
      <div class="el-aside__logo">
        <img src="@/assets/logo2.svg" alt="Logo" style="width: 150px; margin: 20px auto;">
      </div>
      <el-menu active-text-color="#ffd04b" background-color="#232323" text-color="#fff" router>
        <el-menu-item index="/order/control">
          <el-icon>
            <Management/>
          </el-icon>
          <span>订单管理</span>
        </el-menu-item>
        <el-menu-item index="/order/static">
          <el-icon>
            <Promotion/>
          </el-icon>
          <span>订单统计</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <!-- 右侧主区域 -->
    <el-container>
      <!-- 头部区域 -->
      <el-header style="background-color:cornflowerblue; color: white; padding: 10px 20px;">
        <div style="display: flex;justify-content: space-between; align-items: center;">
          <el-button @click="router.push('/')" style="height: 25px">
          <el-icon><ArrowLeft /></el-icon>
          </el-button>
          <div style="margin-left: 10px">用户名 : <strong>{{ userInfo.userName }}</strong></div>
        </div>
      </el-header>
      <!-- 中间区域 -->
      <el-main>
        <!--        使用路由管理的子路由功能进行设计-->
        <router-view></router-view>
      </el-main>
      <!-- 底部区域 -->
      <el-footer style="text-align: center;">数据库原理实验四 Forever</el-footer>
    </el-container>
  </el-container>
</template>

<script setup>
import {onMounted, ref} from 'vue';
import {useRouter} from 'vue-router';
import {Management, Promotion, User, CaretBottom, SwitchButton, ArrowLeft}
  from '@element-plus/icons-vue';
import {supplierTokenStore, useTokenStore, isLoginStore} from "@/store/tokenStore.js";
import {getUserInfo} from "@/api/user.js";
import {ElButton} from "element-plus";

const userInfo = ref({});
const router = useRouter();
const useToken = useTokenStore()
onMounted(() => {
  if (useToken.token === '') {
    supplierTokenStore().clearSupplierToken()
    isLoginStore().resetLogin(false)
  } else {
    getSupplierInfoDetail();
  }
});
const supplierLoginOut = () => {
  useToken.clearToken()
  isLoginStore().resetLogin(false)
  router.push('/');
}
const getSupplierInfoDetail = async () => {
  userInfo.value = await getUserInfo();
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
}

.el-aside__logo {
  text-align: center;
}

.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-main {
  padding: 20px;
}

.el-table {
  margin-bottom: 20px;
}

.el-main {
  height: calc(100vh - 80px); /* 固定高度，减去头部和底部的高度 */
  padding: 20px;
  overflow: auto; /* 如果内容超出可滚动 */
}

router-view {
  height: 100%; /* 使 router-view 填满整个父容器 */
}
</style>